﻿using System;
using System.Windows.Controls;
using System.Windows.Documents;
using ShadeTree.Binding.Elements;

namespace ShadeTree.Binding.WPF
{
    public class LinkLabelElement : BoundScreenElement<ContentControl, object>
    {
        private Hyperlink _link;

        public LinkLabelElement(Accessor accessor, ContentControl control) : base(accessor, control)
        {
            _link = new Hyperlink();
            control.Content = _link;
        }


        protected override bool validatesOnLostFocus()
        {
            return false;
        }

        protected override object getValueFromControl()
        {
            return GetValue();
        }

        protected override void resetControl(object originalValue)
        {
            _link.Inlines.Clear();
            _link.Inlines.Add(originalValue.ToString());
        }

        protected override void tearDown()
        {
            
        }

        public void OnClick(Action action)
        {
            _link.Click += delegate { action(); };
        }
    }
}
